package com.gh.netty.server.handler;

import org.apache.log4j.Logger;

import java.util.List;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageDecoder;

/**
 * @author hugx
 * @create 2018-09-29 15:59
 */
public class TimeDecoder extends ByteToMessageDecoder { // (1)
    private static final Logger log=Logger.getLogger(TimeDecoder.class);
    @Override
    protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) { // (2)
        log.info("decode() of TimeDecoder 1 , len: "+in.readableBytes());
        if (in.readableBytes() < 4) {
            log.info("decode() of TimeDecoder  2 ");
            return; // (3)
        }

        log.info("decode() of TimeDecoder  3 ");
//        out.add(in.readBytes(4)); // (4)
        out.add(in); // (4)
    }
}
